(function($) {

//var plugin = $.GeneralEventPlugin = {
//	//Nom de la classe à instancier /!\ CE NOM DOIT ETRE UNIQUE ET IDENTIQUE AU NOM JQUERY /!\
//	name: 'GeneralEventPlugin'
//};

//Constructeur
var GeneralEventPlugin = function(options){ // rajouter element
	//console.log(this);
	if(arguments.length) {
		this._init( options );// rajouter element
	} else 
		console.log('Aucun paramètre reçu pour GeneralEventPlugin');
};

GeneralEventPlugin.prototype = {
	name: 'GeneralEventPlugin',
	
	defaults: {
		options:{}
	},
	
	_init: function(options){
		var t = this;

		t.settings = $.extend(true, {}, t.defaults, options);
		t.element = (typeof t.settings.element != 'undefined') ? $(t.settings.element) : null;	
				
		var datetime;

		$(t.element).html(t.settings.content);
		
		$('#plug-general-save').on( 'click', function(e) {
			e.preventDefault();
	        $('#plug-general-save, #plug-general-undo, #plug-general-cancel').attr('disabled', true);
	        $("#imt_event_form_general").submit();
	    });
		
		$('#plug-general-undo').on( 'click', function(e) {
			$('#imt_event_form_general_date_date_edit').html(
				$('#imt_event_form_general_date_date_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
			);
			
			$('#imt_event_form_general_date_time_edit').html(
				$('#imt_event_form_general_date_time_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
			);
			
			$('#imt_event_form_general_dateFin_date_edit').html(
				$('#imt_event_form_general_dateFin_date_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
			);
			
			$('#imt_event_form_general_dateFin_time_edit').html(
				$('#imt_event_form_general_dateFin_time_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
			);
	    });
		
		$('#plug-general-edit').on('click', function(e){
			e.preventDefault();
			t.refreshDates();
			
			$('.form-view, .form-edit').toggle(); 
			$(this).parents('li').toggle();
		});
		
		$('#plug-general-delete').on('click', function(e){
			e.preventDefault();
			
			var t = $(this);
			
			$.msgbox("Etes vous certain de vouloir supprimer définitivement cet événement ?", {
		        type: "confirm",
		        buttons: [{
		            type: "submit",
		            value: "Oui"
		        }, {
		            type: "submit",
		            value: "Non"
		        }, {
		            type: "cancel",
		            value: "Annuler"
		        }]
		    }, function (value) {
		    	$.msgbox('choix : '+value+' (suppression à faire ...)');
		    });
		});
		
		$('#imt_event_form_general_allDay').on('click', function(e){
			t.refreshDates();	
		});
		
		$('#plug-general-dateFin-edit').on('click', function(e){
			e.preventDefault();
			if(datetime){
				$('#plug-general-datetime-picker').datetimepicker("destroy");
				datetime = null;
			}
				
			datetime = $('#plug-general-datetime-picker').datetimepicker({
				prevText: "Précedent",
	            nextText: "Suivant",
	            currentText: "Aujourd\'hui",
	            monthNames: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aoüt", "Septembre", "Octobre", "Novembre", "Décembre"],
	            monthNamesShort: ["Jan", "Fév", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],
	            dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
	            dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
	            dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
	            weekHeader: "Wk",
	            dateFormat: "yy-mm-dd",
	            hour: $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4'),
	            minute: $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$5'),
	            firstDay: 1,
	            ampm: false,
	            timeFormat: "hh:mm",
	            timeText: "Fin",
	            hourText: "Heure",
	            minuteText: "Minute",
	            showButtonPanel: false,
	            defaultDate: $('#imt_event_form_general_dateFin').val(),
		        onSelect: function (time, g) {
		        	$('#imt_event_form_general_dateFin').val(time+':00');
		            t.refreshDates();
		        }
	        });

			$("#modal-timepicker").dialog("open");
		});
		
		$('#plug-general-date-edit').on('click', function(e){
			e.preventDefault();
			if(datetime){
				$('#plug-general-datetime-picker').datetimepicker("destroy");
				datetime = null;
			}
				
			datetime = $('#plug-general-datetime-picker').datetimepicker({
				prevText: "Précedent",
	            nextText: "Suivant",
	            currentText: "Aujourd\'hui",
	            monthNames: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aoüt", "Septembre", "Octobre", "Novembre", "Décembre"],
	            monthNamesShort: ["Jan", "Fév", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],
	            dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
	            dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
	            dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
	            weekHeader: "Wk",
	            dateFormat: "yy-mm-dd",
	            hour: $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4'),
	            minute: $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$5'),
	            firstDay: 1,
	            ampm: false,
	            timeFormat: "hh:mm",
	            timeText: "Début",
	            hourText: "Heure",
	            minuteText: "Minute",
	            showButtonPanel: false,
	            defaultDate: $('#imt_event_form_general_date').val(),
		        onSelect: function (time, g) {
		        	$('#imt_event_form_general_date').val(time+':00');
		            t.refreshDates();
		        }
	        });

			$("#modal-timepicker").dialog("open");
		});
		
		$("#modal-timepicker").dialog({
	        autoOpen: false,
	        width: 235,
	        height: 'auto',
	        resizable: false
	    });
		
	    //d("#dp-02-target").text(d.datepicker.formatDate("mm/dd/yy", f.datepicker("getDate")))
		
		$('#plug-general-cancel').on('click', function(e){
			e.preventDefault();
			$('.form-view, .form-edit').toggle(); 
			$('#plug-general-edit').parents('li').toggle();
		});
		
		$("#imt_event_form_general").validate({
	        rules: {
	        	imt_event_form_general_title: {
	                required: true
	            }
	        },
	        submitHandler: function(form) { 
	        	try {        		
		        	var dataSend = {};
		        	
		        	$(
		        		'#imt_event_form_general input[name^=imt_event_form_general], '+
		        		'#imt_event_form_general textarea[name^=imt_event_form_general], '+
		        		'#imt_event_form_general select[name^=imt_event_form_general]'
		        	).each(function(){
		        		var $input = $(this);
		        		
		        		if($input.is('input')){
			        		var typeInput = $input.attr('type');
			        		
			        		if(typeInput == 'checkbox'){
			        			dataSend[$input.attr('id')] = $input.is(':checked') ? 1 : 0;
			        		} else if(typeInput == 'text') {
			        			dataSend[$input.attr('id')] = $input.val();
			        		}
		        		} else if($input.is('textarea')){
		        			dataSend[$input.attr('id')] = $input.val();
		        		} else if($input.is('select')){
		        			dataSend[$input.attr('id')] = $input.val();
		        		}
		        	});

		        	$('#plug-general-loader').html('Sauvegarde en cours ...');
		        	// Vérrouillage du script
	        		loaderManager.lock('em-general-plugin-edit');
	        		
		        	$.ajax({
		        		type: 'POST',
		        		url: $('#imt_event_form_general').attr('action'),
		    		  	data: dataSend,
		    		    dataType: "json"
		        	}).done(function(jsonResult) {
		        		if(jsonResult && typeof jsonResult.result != 'undefined'){
			        		if(jsonResult.result == 200){
			        			t.onFinishSubmitEvent(jsonResult, dataSend);		        			
			        		} else if(jsonResult.result == 400){
			        			$.pnotify({
			                        title: "Erreur de validation !",
			                        text: jsonResult.msg,
			                        type: "error"
			                    });
			        		} else if(jsonResult.result == 500){
			        			$.pnotify({
			                        title: "Erreur !",
			                        text: jsonResult.msg,
			                        type: "error"
			                    });
			        		}
		        		} else {
		            		alert('La réponse du serveur est incorrecte');
		            	}
		        	}).fail(function(jqXHR, textStatus, errorThrown) {
		        		alert('Une erreur est survenue ('+errorThrown+')');
		        	}).always(function(jqXHR, textStatus, errorThrown) {
		        		$('#plug-general-loader').html('');
		        		$('#plug-general-save, #plug-general-undo, #plug-general-cancel').attr('disabled', false);
		        		loaderManager.unlock('em-general-plugin-edit');
		        	});
	        	} catch(e){
	        		alert('Une erreur inconnue est survenue ('+e+')');
	        	}
	    	}
	    });	
		
		if($('#eventManager').data('eventManager').baseEvent.event.isNew){
			$('#plug-general-edit').click();
			$('#plug-general-actions').hide();
			$('#plug-general-cancel').hide();
		}
	},
	
	refreshDates : function (){
		$('#imt_event_form_general_date_date_edit').html(
			$('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
		);
		
		$('#imt_event_form_general_date_time_edit').html(
			$('#imt_event_form_general_allDay').is(':checked') ? '00:00' : $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
		);
		
		$('#imt_event_form_general_dateFin_date_edit').html(
			$('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
		);
		
		$('#imt_event_form_general_dateFin_time_edit').html(
			$('#imt_event_form_general_allDay').is(':checked') ? '00:00' : $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
		);
	},
	
	refreshView : function(data){
		$.each(data, function(id, value){
			if(id == 'imt_event_form_general_allDay')
				$('#'+id+'_view').html(value ? '<span class="badge badge-success">Oui</span>' : '<span class="badge">Non</span>');			
			else if(id == 'imt_event_form_general_date' || id == 'imt_event_form_general_dateFin'){
				$('#'+id+'_date_view').html(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
				$('#'+id+'_time_view').html($('#imt_event_form_general_allDay').is(':checked') ? '00:00' : value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5'));
			} else {
				$('#'+id+'_view').html(value);
			}
			
			if(id == 'imt_event_form_general_title')
				$('#eventManager').data('eventManager').baseEvent.event.header.setTitle(value);
			else if(id == 'imt_event_form_general_date')
				$('#eventManager').data('eventManager').baseEvent.event.header.setStringDate(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
			else if(id == 'imt_event_form_general_dateFin')
				$('#eventManager').data('eventManager').baseEvent.event.header.setStringDateFin(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
			
		});
		
		$('#eventManager').data('eventManager').baseEvent.event.header.render();
	},
	
	onFinishSubmitEvent : function(jsonResult, dataSend){
		$.pnotify({
	        title: "Terminé !",
	        text: jsonResult.msg,
	        type: "success"
	    });
		
		if(typeof jsonResult.refresh != 'undefined'){
			document.location.href = jsonResult.refresh;
			return;
		} else {
			this.refreshView(dataSend);
			$('#plug-general-cancel').click();
		}
	}
};

$.fn.pluginGeneralEvent = function(options) {

	var isMethodCall = typeof options === "string",
		args = Array.prototype.slice.call( arguments, 1 ),
		returnValue = this;

	// prevent calls to internal methods
	if ( isMethodCall && options.charAt( 0 ) === "_" ) {
		return returnValue;
	}

	if ( isMethodCall ) {
		this.each(function() {
			var instance = $.data( this, 'GeneralEventPlugin' ),
				methodValue = instance && $.isFunction( instance[options] ) ?
					instance[ options ].apply( instance, args ) :
					instance;

			if ( methodValue !== instance && methodValue !== undefined ) {
				returnValue = methodValue;
				return false;
			}
		});
	} else {
		this.each(function() {
			var instance = $.data( this, 'GeneralEventPlugin' );
			if ( !instance ) {
				$.data( this, 'GeneralEventPlugin', new GeneralEventPlugin( this, options ) );
			}
		});
	}

	return returnValue;
};

//plugin.manager = function(_settings) {
//	var t = this;
//
//	var defaults = {
//		options:{},
//	};
//
//	t.settings = $.extend(true, {}, defaults, _settings);
//	t.element = (typeof t.settings.element != 'undefined') ? $(t.settings.element) : null;	
//	
//	t.refreshView = refreshView;
//	
//	// Si aucun element du DOM n'a été spécifié le plugin est rattaché à l'element appelant
//	if(!t.element){
//		this.each(function(i, _element){
//			t.element = $(_element);
//		});
//	}
//
//	var manager = new GeneralEvent(t);
//	
//	return this;	
//};
//
//function GeneralEvent(_plugin){
//	var t = this;
//	var plugin = _plugin;
//	var datetime;
//
//	$(plugin.element).html(plugin.settings.content);
//	
//	$('#plug-general-save').on( 'click', function(e) {
//		e.preventDefault();
//        $('#plug-general-save, #plug-general-undo, #plug-general-cancel').attr('disabled', true);
//        $("#imt_event_form_general").submit();
//    });
//	
//	$('#plug-general-undo').on( 'click', function(e) {
//		$('#imt_event_form_general_date_date_edit').html(
//			$('#imt_event_form_general_date_date_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
//		);
//		
//		$('#imt_event_form_general_date_time_edit').html(
//			$('#imt_event_form_general_date_time_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
//		);
//		
//		$('#imt_event_form_general_dateFin_date_edit').html(
//			$('#imt_event_form_general_dateFin_date_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
//		);
//		
//		$('#imt_event_form_general_dateFin_time_edit').html(
//			$('#imt_event_form_general_dateFin_time_edit').next('input').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
//		);
//    });
//	
//	$('#plug-general-edit').on('click', function(e){
//		e.preventDefault();
//		refreshDates();
//		
//		$('.form-view, .form-edit').toggle(); 
//		$(this).parents('li').toggle();
//	});
//	
//	$('#plug-general-delete').on('click', function(e){
//		e.preventDefault();
//		
//		var t = $(this);
//		
//		$.msgbox("Etes vous certain de vouloir supprimer définitivement cet événement ?", {
//	        type: "confirm",
//	        buttons: [{
//	            type: "submit",
//	            value: "Oui"
//	        }, {
//	            type: "submit",
//	            value: "Non"
//	        }, {
//	            type: "cancel",
//	            value: "Annuler"
//	        }]
//	    }, function (value) {
//	    	$.msgbox('choix : '+value+' (suppression à faire ...)');
//	    });
//	});
//	
//	$('#imt_event_form_general_allDay').on('click', function(e){
//		refreshDates();	
//	});
//	
//	$('#plug-general-dateFin-edit').on('click', function(e){
//		e.preventDefault();
//		if(datetime){
//			$('#plug-general-datetime-picker').datetimepicker("destroy");
//			datetime = null;
//		}
//			
//		datetime = $('#plug-general-datetime-picker').datetimepicker({
//			prevText: "Précedent",
//            nextText: "Suivant",
//            currentText: "Aujourd\'hui",
//            monthNames: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aoüt", "Septembre", "Octobre", "Novembre", "Décembre"],
//            monthNamesShort: ["Jan", "Fév", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],
//            dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
//            dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
//            dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
//            weekHeader: "Wk",
//            dateFormat: "yy-mm-dd",
//            hour: $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4'),
//            minute: $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$5'),
//            firstDay: 1,
//            ampm: false,
//            timeFormat: "hh:mm",
//            timeText: "Fin",
//            hourText: "Heure",
//            minuteText: "Minute",
//            showButtonPanel: false,
//            defaultDate: $('#imt_event_form_general_dateFin').val(),
//	        onSelect: function (time, g) {
//	        	$('#imt_event_form_general_dateFin').val(time+':00');
//	            refreshDates();
//	        }
//        });
//
//		$("#modal-timepicker").dialog("open");
//	});
//	
//	$('#plug-general-date-edit').on('click', function(e){
//		e.preventDefault();
//		if(datetime){
//			$('#plug-general-datetime-picker').datetimepicker("destroy");
//			datetime = null;
//		}
//			
//		datetime = $('#plug-general-datetime-picker').datetimepicker({
//			prevText: "Précedent",
//            nextText: "Suivant",
//            currentText: "Aujourd\'hui",
//            monthNames: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aoüt", "Septembre", "Octobre", "Novembre", "Décembre"],
//            monthNamesShort: ["Jan", "Fév", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],
//            dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
//            dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
//            dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
//            weekHeader: "Wk",
//            dateFormat: "yy-mm-dd",
//            hour: $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4'),
//            minute: $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$5'),
//            firstDay: 1,
//            ampm: false,
//            timeFormat: "hh:mm",
//            timeText: "Début",
//            hourText: "Heure",
//            minuteText: "Minute",
//            showButtonPanel: false,
//            defaultDate: $('#imt_event_form_general_date').val(),
//	        onSelect: function (time, g) {
//	        	$('#imt_event_form_general_date').val(time+':00');
//	            refreshDates();
//	        }
//        });
//
//		$("#modal-timepicker").dialog("open");
//	});
//	
//	$("#modal-timepicker").dialog({
//        autoOpen: false,
//        width: 235,
//        height: 'auto',
//        resizable: false
//    });
//	
//    //d("#dp-02-target").text(d.datepicker.formatDate("mm/dd/yy", f.datepicker("getDate")))
//	
//	$('#plug-general-cancel').on('click', function(e){
//		e.preventDefault();
//		$('.form-view, .form-edit').toggle(); 
//		$('#plug-general-edit').parents('li').toggle();
//	});
//	
//	$("#imt_event_form_general").validate({
//        rules: {
//        	imt_event_form_general_title: {
//                required: true
//            }
//        },
//        submitHandler: function(form) { 
//        	try {        		
//	        	var dataSend = {};
//	        	
//	        	$(
//	        		'#imt_event_form_general input[name^=imt_event_form_general], '+
//	        		'#imt_event_form_general textarea[name^=imt_event_form_general], '+
//	        		'#imt_event_form_general select[name^=imt_event_form_general]'
//	        	).each(function(){
//	        		var $input = $(this);
//	        		
//	        		if($input.is('input')){
//		        		var typeInput = $input.attr('type');
//		        		
//		        		if(typeInput == 'checkbox'){
//		        			dataSend[$input.attr('id')] = $input.is(':checked') ? 1 : 0;
//		        		} else if(typeInput == 'text') {
//		        			dataSend[$input.attr('id')] = $input.val();
//		        		}
//	        		} else if($input.is('textarea')){
//	        			dataSend[$input.attr('id')] = $input.val();
//	        		} else if($input.is('select')){
//	        			dataSend[$input.attr('id')] = $input.val();
//	        		}
//	        	});
//
//	        	$('#plug-general-loader').html('Sauvegarde en cours ...');
//	        	// Vérrouillage du script
//        		loaderManager.lock('em-general-plugin-edit');
//        		
//	        	$.ajax({
//	        		type: 'POST',
//	        		url: $('#imt_event_form_general').attr('action'),
//	    		  	data: dataSend,
//	    		    dataType: "json"
//	        	}).done(function(jsonResult) {
//	        		if(jsonResult && typeof jsonResult.result != 'undefined'){
//		        		if(jsonResult.result == 200){
//		        			$.GeneralEventPlugin.onFinishSubmitEvent(jsonResult, dataSend);		        			
//		        		} else if(jsonResult.result == 400){
//		        			$.pnotify({
//		                        title: "Erreur de validation !",
//		                        text: jsonResult.msg,
//		                        type: "error"
//		                    });
//		        		} else if(jsonResult.result == 500){
//		        			$.pnotify({
//		                        title: "Erreur !",
//		                        text: jsonResult.msg,
//		                        type: "error"
//		                    });
//		        		}
//	        		} else {
//	            		alert('La réponse du serveur est incorrecte');
//	            	}
//	        	}).fail(function(jqXHR, textStatus, errorThrown) {
//	        		alert('Une erreur est survenue ('+errorThrown+')');
//	        	}).always(function(jqXHR, textStatus, errorThrown) {
//	        		$('#plug-general-loader').html('');
//	        		$('#plug-general-save, #plug-general-undo, #plug-general-cancel').attr('disabled', false);
//	        		loaderManager.unlock('em-general-plugin-edit');
//	        	});
//        	} catch(e){
//        		alert('Une erreur inconnue est survenue ('+e+')');
//        	}
//    	}
//    });	
//	
//	if($('#eventManager').data('eventManager').baseEvent.event.isNew){
//		$('#plug-general-edit').click();
//		$('#plug-general-actions').hide();
//		$('#plug-general-cancel').hide();
//	}
//	
//	function refreshDates(){
//		$('#imt_event_form_general_date_date_edit').html(
//			$('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
//		);
//		
//		$('#imt_event_form_general_date_time_edit').html(
//			$('#imt_event_form_general_allDay').is(':checked') ? '00:00' : $('#imt_event_form_general_date').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
//		);
//		
//		$('#imt_event_form_general_dateFin_date_edit').html(
//			$('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1')
//		);
//		
//		$('#imt_event_form_general_dateFin_time_edit').html(
//			$('#imt_event_form_general_allDay').is(':checked') ? '00:00' : $('#imt_event_form_general_dateFin').val().replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5')
//		);
//	}
//}
//
//function refreshView(data){
//	$.each(data, function(id, value){
//		if(id == 'imt_event_form_general_allDay')
//			$('#'+id+'_view').html(value ? '<span class="badge badge-success">Oui</span>' : '<span class="badge">Non</span>');			
//		else if(id == 'imt_event_form_general_date' || id == 'imt_event_form_general_dateFin'){
//			$('#'+id+'_date_view').html(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
//			$('#'+id+'_time_view').html($('#imt_event_form_general_allDay').is(':checked') ? '00:00' : value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$4:$5'));
//		} else {
//			$('#'+id+'_view').html(value);
//		}
//		
//		if(id == 'imt_event_form_general_title')
//			$('#eventManager').data('eventManager').baseEvent.event.header.setTitle(value);
//		else if(id == 'imt_event_form_general_date')
//			$('#eventManager').data('eventManager').baseEvent.event.header.setStringDate(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
//		else if(id == 'imt_event_form_general_dateFin')
//			$('#eventManager').data('eventManager').baseEvent.event.header.setStringDateFin(value.replace(/(\d{4})-(\d{2})-(\d{2}).(\d{2}):(\d{2}):(\d{2})/,'$3/$2/$1'));
//		
//	});
//	
//	$('#eventManager').data('eventManager').baseEvent.event.header.render();
//}
//
//plugin.onFinishSubmitEvent = function(jsonResult, dataSend){
//	console.log('general');
//	$.pnotify({
//        title: "Terminé !",
//        text: jsonResult.msg,
//        type: "success"
//    });
//	
//	if(typeof jsonResult.refresh != 'undefined'){
//		document.location.href = jsonResult.refresh;
//		return;
//	} else {
//		$.GeneralEventPlugin.refreshView(dataSend);
//		$('#plug-general-cancel').click();
//	}
//};

// Association en tant que plugin jQuery
//$.fn.GeneralEventPlugin = plugin.GeneralEventPlugin;

// Si l'eventManager a été déclaré on le surcharge pour la gestion du plugin
if(typeof $.eventManager != 'undefined'){
	var em = $.eventManager;
	
	// Ajout du plugin au register du manager, il sera instancié par le manager automatiquement
	//em.addPluginToRegister(plugin.name, plugin.manager);
	em.addPluginToRegister('GeneralEventPlugin', GeneralEventPlugin);
}

})(jQuery);